package com.captjack.micro.web.admin;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.Banner;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * EnableHystrixDashboard注解 开启hystrixDashboard Hystrix Dashboard (断路器：Hystrix 仪表盘)
 *
 * @author Administrator
 */
@SpringCloudApplication
@EnableFeignClients(basePackages = {"com.captjack.micro.api"})
@EnableHystrix
@ComponentScan(basePackages = {"com.captjack.micro.web.admin", "com.captjack.micro.api"})
public class AdminWebApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(AdminWebApplication.class).bannerMode(Banner.Mode.CONSOLE).run(args);
    }

    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }

}
